package game.player;

import game.driver.Controller;

import game.model.Deck;

import game.model.Card;

import java.awt.Color;

import java.util.ArrayList;


/**
 * Will allow the controller to have acces he player moves and will sincronize
 * player moves.
 * 
 * @author Maria
 * 
 */
public class Player {

	private String name;
	protected ArrayList<Card> mycards;
	protected Card card;
	protected Deck down;
	protected Controller control;
	private int difficulty;

	StringBuffer sb = new StringBuffer();

	protected ArrayList<Card> myYellow;

	protected ArrayList<Card> myGreen;

	protected ArrayList<Card> myRed;

	protected ArrayList<Card> myBlue;

	protected ArrayList<Card> myWild;

	/**
	 * 
	 * Constructor
	 * 
	 * 
	 * 
	 * 
	 @param controller
	 * 
	 * 
	 @param name
	 */

	public Player(Controller controller, String name,int dif) {

		mycards = new ArrayList<Card>();

		controller = control;

		this.name = name;

		myYellow = new ArrayList<Card>();

		myGreen = new ArrayList<Card>();

		myRed = new ArrayList<Card>();

		myBlue = new ArrayList<Card>();

		myWild = new ArrayList<Card>();
	dif= difficulty;

	}

	/**
	 * 
	 * get how many cards you have
	 * 
	 * 
	 * 
	 * 
	 @return
	 */

	public int size() {

		return mycards.size();

	}

	/**
	 * 
	 * Add the cards that are distributed to players.
	 * 
	 * 
	 * 
	 * 
	 @param c
	 * 
	 * 
	 */

	public void addCards(Card[] c) {

		for (int i = 0; i < c.length; i++) {

			mycards.add(c[i]);

		}

	}

	/**
	 * 
	 * get the card the player has and remove from its hand.
	 * 
	 * 
	 * 
	 * 
	 @param c
	 * 
	 * 
	 @return
	 */

	public Card getCard(Card c) {

		mycards.remove(c);
		if (c.getColor().equals(Color.GREEN)){
      for(int i =0; i<mycards.size();i++)
    	  if(mycards.get(i).equals(c))
			myGreen.remove(c);}
		else if (c.getColor().equals(Color.YELLOW)){
			 for(int i =0; i<mycards.size();i++)
		    	  if(mycards.get(i).equals(c))
			myYellow.remove(c);}
		else if (c.getColor().equals(Color.BLUE)){
			 for(int i =0; i<mycards.size();i++)
		    	  if(mycards.get(i).equals(c))
			myBlue.remove(c);}
		else if (c.getColor().equals(Color.RED)){
			 for(int i =0; i<mycards.size();i++)
		    	  if(mycards.get(i).equals(c))
			myRed.remove(c);}
		else if (c.getColor().equals(Color.BLACK)){
			 for(int i =0; i<mycards.size();i++)
		    	  if(mycards.get(i).equals(c))
			myWild.remove(c);
		}

		return c;

	}

	/**
	 * 
	 * get the cards and return them in color
	 * 
	 * - value.
	 * 
	 * 
	 * 
	 * 
	 @return
	 */

	public StringBuffer getAllCards() {

		for (int i = 0; mycards.size() < i; i++) {

			sb.append(card.getColor());

			sb.append(" ");

			sb.append("-");

			sb.append(card.getValue());

			sb.append(",");

			sb.append(" ");

		}

		sb.toString();

		return sb;

	}

	/**
	 * 
	 * check if the player has cards or not.
	 * 
	 * 
	 * 
	 * 
	 @return
	 */

	public boolean hasCard(Card c) {

		if (mycards.size() != 0)

			return true;

		else

			return false;

	}

	/**
	 * 
	 * check if the player is a human player or not .
	 * 
	 * 
	 * 
	 * 
	 @return
	 */

	public boolean isHuman() {

		if (this.getDifficulty()==-1)

			return true;

		else

			return false;

	}

	/**
	 * 
	 * get the player name.
	 * 
	 * 
	 * 
	 * 
	 @return
	 */

	public final String getName() {

		return name;

	}

	public void drawCards(Card c) {
		mycards.add(c);
		if (c.getColor().equals(Color.GREEN))

			myGreen.add(c);
		else if (c.getColor().equals(Color.YELLOW))

			myYellow.add(c);
		else if (c.getColor().equals(Color.BLUE))

			myBlue.add(c);
		else if (c.getColor().equals(Color.RED))

			myRed.add(c);
		else if (c.getColor().equals(Color.BLACK))

			myWild.add(c);
	}

	/**
	 * return array of Yellow the player has
	 * 
	 * @return
	 */
	public ArrayList<Card> getYellow() {

		return myYellow;

	}

	/**
	 * return array of Green cards the player has
	 * 
	 * @return
	 */
	public ArrayList<Card> getGreen() {

		return myGreen;

	}

	/**
	 * return array of red colors the player has
	 * 
	 * @return
	 */
	public ArrayList<Card> getRed() {

		return myRed;

	}

	/**
	 * return array of Blue cards the player has
	 * 
	 * @return
	 */
	public ArrayList<Card> getBlue() {

		return myBlue;

	}

	/**
	 * return array of Wild cards the player has.
	 * 
	 * @return
	 */
	public ArrayList<Card> getWild() {

		return myWild;

	}

	/**
	 * Return number of Cards.
	 * 
	 * @return
	 */
	public int hasNumCards() {

		return mycards.size();

	}
	public int getDifficulty() {
		
		return difficulty;
	}
	public Card play(Card c){
		return c;
	}
	public Card makePlay(Card c){
		return c;
	}
} // end of class
